package net.zjitc.servlet;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Created by hasee on 2017/9/26.
 */
@WebServlet(name = "HttpServletOne",urlPatterns = "/s1")
public class HttpServletOne extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();

//        response.sendRedirect("/homework/s2");//重定向到s2(给客户端一个URI,让客户端自己再访问)

//        RequestDispatcher requestDispatcher = request.getRequestDispatcher("/s3");//请求转发(服务器自己找到一个servlet，让它解决)
//        requestDispatcher.forward(request,response);

        out.write("我是s1，我要s3帮我"+"</br>");
        RequestDispatcher requestDispatcher = request.getRequestDispatcher("/s3");//请求包含(自己先解决一部分,之后交给别人处理) 请求头必须写在访问的servlet里
        requestDispatcher.include(request,response);
    }
}
